﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Componnent.Common;

using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Core.Repository.BasicSet;
using WaterRevenueMS.Domain.ViewModels.BasicSet;

namespace WaterRevenueMS.Core.Service.BasicSet.Impl
{
    [Export(typeof(ICompanySetService))]
    public class CompanySetService : CoreServiceBase, ICompanySetService
    {
        [Import]
        public ICompanySetRepository CompanySetRepository { get; set; }


        public IQueryable<CompanySet> CompanySets
        {
            get { return CompanySetRepository.Entities; }
        }

        public OperationResult Insert(Domain.ViewModels.BasicSet.CompanySet.CompanySetModel model)
        {
            var entity = new CompanySet
            {

                Yin_HSZ_No = model.Yin_HSZ_No != 0 ? model.Yin_HSZ_No : null,

                Gong_SBZ = model.Gong_SBZ,
                Dan_WMC = model.Dan_WMC,
                Dan_WJC = model.Dan_WJC,
                Dan_WMCE = model.Dan_WMCE,
                Dan_WDZ = model.Dan_WDZ,
                Dian_H = model.Dian_H,
                Chuan_Z = model.Chuan_Z,
                Fu_ZR = model.Fu_ZR,
                Lian_XR = model.Lian_XR,
                You_ZBM = model.You_ZBM,
                Qi_YZY = model.Qi_YZY,
                Qi_YYX = model.Qi_YYX,
                Yin_HZH = model.Yin_HZH,
                Shui_H = model.Shui_H,

                CreateDT = DateTime.Now,

                ReviseDT = DateTime.Now

            };
            CompanySetRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(Domain.ViewModels.BasicSet.CompanySet.CompanySetModel model)
        {
            var entity = new CompanySet
            {
                Id = model.Id,
                Yin_HSZ_No = model.Yin_HSZ_No != 0 ? model.Yin_HSZ_No : null,

                Gong_SBZ = model.Gong_SBZ,
                Dan_WMC = model.Dan_WMC,
                Dan_WJC = model.Dan_WJC,
                Dan_WMCE = model.Dan_WMCE,
                Dan_WDZ = model.Dan_WDZ,
                Dian_H = model.Dian_H,
                Chuan_Z = model.Chuan_Z,
                Fu_ZR = model.Fu_ZR,
                Lian_XR = model.Lian_XR,
                You_ZBM = model.You_ZBM,
                Qi_YZY = model.Qi_YZY,
                Qi_YYX = model.Qi_YYX,
                Yin_HZH = model.Yin_HZH,
                Shui_H = model.Shui_H,

                CreateDT = DateTime.Now,

                ReviseDT = DateTime.Now

            };
            CompanySetRepository.Update(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Delete(int Id)
        {
            var model = CompanySets.FirstOrDefault(t => t.Id == Id);
            model.IsDeleted = true;

            CompanySetRepository.Update(model);
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
